<template>
  <div class="feedBack flex">
    <div v-if="isRequesting" class="feedBack-loading"></div>
    <div class="feedBack-error" v-else-if="isError">
      <SvgIcon icon-class="error" popper-class="icon-error" />
      <span class="feedBack-error__desc">{{ message }}</span>
      <div class="retry">
        <el-button style="width: 60%" type="danger" @click="emits('retry')" plain
          >重试</el-button
        >
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
defineProps<{
  isRequesting: boolean;
  isError: boolean;
  message: string;
}>();

const emits = defineEmits<{
  (e: "retry"): void;
}>();
</script>

<style lang="scss" scoped>
$loadBackg: #fc6e6e;

@keyframes rectangle {
  0%,
  80%,
  100% {
    height: 20px;
    box-shadow: 0 0 $loadBackg;
  }

  40% {
    height: 30px;
    box-shadow: 0 -20px $loadBackg;
  }
}

.feedBack {
  @include setWidHei(100%, 100%);

  &-loading {
    position: relative;
    width: 6px;
    height: 10px;
    animation: rectangle infinite 1s ease-in-out -0.2s;
    background-color: $loadBackg;

    &::before {
      left: -14px;
      animation: rectangle infinite 1s ease-in-out -0.4s;
    }

    &::after {
      right: -14px;
      animation: rectangle infinite 1s ease-in-out;
    }

    &::before,
    &::after {
      position: absolute;
      width: 6px;
      height: 10px;
      content: "";
      background-color: $loadBackg;
    }
  }

  &-error {
    color: #cf3736;
    text-align: center;

    &__desc {
      font-size: 18px;
      margin-left: 15px;
    }

    .retry {
      margin-top: 25px;
      text-align: center;
    }
  }
}
</style>
